﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.Utilities;
using CuaHangMayTinh.DataProvider;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.DataAccessLayer;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// 
    /// </summary>
    public class NhanVienManager
    {
        /// <summary>
        /// 
        /// </summary>
        private static NhanVienDA adapter = null;

        static NhanVienManager()
        {
            if (adapter == null)
                adapter = new NhanVienDA();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(NhanVienEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int Insert(NhanVienEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int InsertGetID(NhanVienEntity entity)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertGetID(NhanVienEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(NhanVienEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool UpDate(NhanVienEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate_TinhTrang(NhanVienEntity entity)
        {
            try
            {
                return adapter.UpDate_TinhTrang(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool UpDate_TinhTrang(NhanVienEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.UpDate_TinhTrang(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ten"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_Ten(string ten, bool View)
        {
            try
            {
                return adapter.Find_Ten(ten, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ten"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_Ten(string ten, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_Ten(ten, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmnd"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_CMND(string cmnd, bool View)
        {
            try
            {
                return adapter.Find_CMND(cmnd, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmnd"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_CMND(string cmnd, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_CMND(cmnd, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int id, bool View)
        {
            try
            {
                return adapter.Find_ID(id, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int id, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_ID(id, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nv"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_NghiepVu(string nv, bool View)
        {
            try
            {
                return adapter.Find_NghiepVu(nv, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nv"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_NghiepVu(string nv, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_NghiepVu(nv, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDSGU"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_SubGroupUser(int IDSGU, bool View)
        {
            try
            {
                return adapter.Find_SubGroupUser(IDSGU, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="IDSGU"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_SubGroupUser(int IDSGU, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_SubGroupUser(IDSGU, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static bool Delete(int ID)
        {
            try
            {
                return adapter.Delete(ID);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool Delete(int ID, ref string errormessage)
        {
            try
            {
                return adapter.Delete(ID);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<NhanVienEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Pass"></param>
        /// <returns></returns>
        public static DataTable DangNhap(string UserName, string Pass)
        {
            try
            {
                return adapter.DangNhap(UserName, Pass);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Pass"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable DangNhap(string UserName, string Pass, ref string errormessage)
        {
            try
            {
                return adapter.DangNhap(UserName, Pass);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }
    }
}
